import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'

/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
const URL_PREFIX = 'middle-goods/'

/**
 * 获取整个商城最新商品
 * @param {String|Number} current 当前页数
 * @param {String | Number} size 每页尺寸
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryNewProductsPage = (current, size, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_detail/queryNewProductsPage', {
    current,
    size
  }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 获取整个商城高点击商品
 * @param {String|Number} current 当前页数
 * @param {String | Number} size 每页尺寸
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryTopProductsPage = (current, size, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_detail/queryNewProductsPage', {
    current,
    size
  }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 获取某个店铺中的最近商品
 * @param {String|Number} id 店铺id
 * @param {String|Number} current 当前页数
 * @param {String | Number} size 每页尺寸
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryStoreRelatedProductPage = (id, current, size, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_detail/queryStoreRelatedProductPage', {
    current,
    size,
    storeId: id
  }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 根据id获取商品详细信息
 * @param {String|Number} id 商品id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryGoodDetailById = (id, successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_detail/queryById', {
    id
  }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 根据id获取商品详细信息
 * @param {PageDTO} pageDTO 条件分页DTO
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryGoodDetailByPage = (pageDTO, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_detail/queryGoodDetailByPage', pageDTO, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}
